<template>
	<view>
		<view class="top-wrap">
			<view class="top">
				<view class="date-wrap">
					<image class="calendar-icon" src="@/static/imgs/icons/calendar1-icon.png" mode="aspectFill"></image>
					<text class="date">{{rentDate}}</text>
				</view>
			</view>
			<view class="address">
				{{rentInfo.choosedStation.from.name}} <text v-if="rentInfo && rentInfo.choosedStation && rentInfo.choosedStation.to &&  rentInfo.choosedStation.to.name"> — {{rentInfo.choosedStation.to.name}}</text>
			</view>
		</view>
		
		<view class="left_navigation-wrap">
			<scroll-view  class="l-wrap" scroll-y="true" >
				<view 
					class="l_item"
					:class="{active: curNav===it_l}"
					v-for="(it_l, in_l) in navList"
					:key="in_l"
					@click="handleChooseCharteredType(it_l, in_l)"
				>
					{{it_l}}
				</view>
			</scroll-view>
			
			<scroll-view class="r-wrap" scroll-y="true">
				<view class="list">
					<view 
						class="item"
						v-for="(item, index) in list"
						:key="index"
					>
						<view class="info-wrap"	@click.stop="handleGoRentOrder(item)">
							<image class="img" :src="item.img" mode="aspectFill"></image>
							<view class="info">
								<view class="name">{{item.name}}</view>
								<view class="intro">{{item.attributes.split('-')[0]}}·{{item.seat}}座·{{item.attributes.split('-')[1]}}</view>
								<view class="price">￥<text style="font-size: 36rpx;font-weight: bold;">{{item.price}}</text>/天</view>
							</view>
						</view>
						<view class="package-wrap">
							<view class="tit-wrap" @click="handleChooseCar(item)">
								<text>套餐</text>
								<uni-icons type="arrowdown" size="24" color="#999" v-if="curCar.id!==item.id"></uni-icons>
								<uni-icons type="arrowup" size="24" color="#999" v-else></uni-icons>
							</view>
							<view class="package_list" :style="{height:curCar.id===item.id?item.taoCanVoList.length*60 +'rpx':'0rpx', paddingBottom: curCar.id===item.id?'20rpx':'0rpx'}">
								<view 
									class="package_item"
									v-for="(it_p, in_p) in item.taoCanVoList"
									:key="in_p"
									@click.stop="handleGoRentOrder(item,it_p)"
								>
									<view class="name-wrap">
										<uni-icons class="circle-icon" type="circle" size="20" color="#999" v-if="curPack && curPack.id!==it_p.id"></uni-icons>
										<uni-icons class="circle-icon" type="circle-filled" size="20" color="#00b4ff" v-else></uni-icons>
										<text>{{it_p.day}}天</text>
									</view>
									<view class="price">￥{{it_p.price}}</view>
								</view>
							</view>
						</view>
						
					</view>
				</view>
				
				<view class="nodata" v-if="!list.length && !list.length">这里还木有数据哈~~</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navList: [],
				curNav: '经济型',
				curChoosedPackage: {}, // 当前所选车型
				list: [], // 符合条件的列表
				curCar: {}, // 当前所选车
				curPack: {}, // 当前所选套餐
			};
		},
		onLoad(opt) {
			this.shopId = opt.shopId && opt.shopId
			this.getRentList()
		},
		computed: {
			rentInfo() {
				return this.$store.getters.getRentInfo
			},
			rentDate() {
				let {month, day} = this.rentInfo.dateObj
				const h = this.rentInfo.dateObj.hour.value
				const m = this.rentInfo.dateObj.minute.value
				return `${month}月${day}日 ${h}:${m}`
			}
		},
		methods: {
			handleChooseCharteredType(item, i) {
				this.curNav = item
				this.list = this.totalList[i].list
			},
			handleGoRentOrder(car,pack) {
				this.curCar = car
				this.curPack = pack
				const carInfo = JSON.stringify(this.curCar)
				const packageInfo = JSON.stringify(this.curPack)
				uni.navigateTo({
					url: '../pages/order/rent.order?carInfo=' + carInfo + '&packageInfo=' + packageInfo
				});
			},
			handleChooseCar(item) {
				this.curCar = item
			},
			getRentList() {
				this.$http.get(this.$api.getRentList + '?shopId=' + this.shopId).then(res => {
					if (res.code === 200) {
						this.list = []
						this.curNav = res.data[0].typeName
						this.totalList = res.data
						
						res.data.forEach(item => { // 获取车类型列表
							this.navList.push(item.typeName)
						})
						this.list = res.data[0].list
						this.curCar = res.data[0].list[0] && res.data[0].list[0].taoCanVoList[0]
					}
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
.top-wrap {
	border-bottom: 1px solid #ebebeb;
	display: flex;
	justify-content: space-evenly;
	flex-direction: column;
	font-size: 24rpx;
	height: 100rpx;
	padding: 0 40rpx 12rpx;
	background-color: #fff;
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 3;
	.top {
		display: flex;
		align-items: center;
		.date-wrap {
			display: flex;
			align-items: center;
			.calendar-icon {
				width: 32rpx;
				height: 32rpx;
				margin-right: 12rpx;
			}
		}
		.person-wrap {
			margin-left: 62rpx;
		}
	}
}

.left_navigation-wrap {
	padding-top: 112rpx;
	display: flex;
	justify-content: space-between;
	position: relative;
	.l-wrap {
		width: 200rpx;
		position: fixed;
		top: 114rpx;
		left: 0;
		bottom: 0;
		z-index: 3;
		.l_item {
			height: 100rpx;
			width: 200rpx;
			display: flex;
			align-items: center;
			justify-content: space-evenly;
			font-size: 32rpx;
			font-weight: bold;
			&.active {
				background-color: #fff;
				position: relative;
				&::after {
					content: '';
					width:8rpx;
					height: 42rpx;
					border-radius: 4rpx;
					background-color: $blue;
					position: absolute;
					top: 50%;
					transform: translateY(-50%);
					left: 0;
				}
			}
		}
	}
	.r-wrap {
		width: 550rpx;
		position: fixed;
		top: 114rpx;
		right: 0;
		bottom: 0;
		flex: 1;
		.list {
			display: flex;
			flex-direction: column;
			.item {
				
				margin-bottom: 20rpx;
				background-color: #fff;
				&:last-child {
					border: none;
				}
				.info-wrap {
					display: flex;
					justify-content: space-between;
					align-items: center;
					height: 160rpx;
					padding: 30rpx 0;
					margin: 0 30rpx;
					border-bottom: 1px solid #ebebeb;
					.img {
						width: 156rpx;
						height: 89rpx;
						background-color: pink;
						margin-right: 36rpx;
					}
					.info {
						flex: 1;
						.name {
							font-size: 30rpx;
						}
						.intro {
							font-size: 24rpx;
							color: #999;
							padding: 20rpx 0;
						}
						.price {
							font-size: 24rpx;
							color: $red;
						}
					}
				}
				.package-wrap {
					padding: 0 30rpx;
					font-size: 28rpx;
					.tit-wrap {
						display: flex;
						height: 84rpx;
						align-items: center;
						justify-content: space-between;
					}
					.package_list {
						overflow: hidden;
						transition: all 0.3s ease;
						.package_item {
							display: flex;
							justify-content: space-between;
							align-items: center;
							height: 60rpx;
							.circle-icon {
								margin-right: 30rpx;
							}
							.name-wrap {
								display: flex;
								align-items: center;
							}
							.price {
								color: $red;
							}
						}
					}
				}
			}
		}
	}
}

.nodata {
	text-align: center;
	color: #999;
	margin: 100rpx auto;
}
</style>
